﻿<UserControl x:Class="TweetsModule.Views.UglyDisplayView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:viewModelLocator="http:\\www.codeplex.com\MEFedMVVM"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:regions="http://www.codeplex.com/CompositeWPF"
             viewModelLocator:ViewModelLocator.SharedViewModel="UglyDisplayViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="850" d:DataContext="{d:DesignData /SampleData/UglyDisplayViewModelSampleData.xaml}">
	<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black" x:Name="MainGrid"
					Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
					Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition />
			<RowDefinition />
		</Grid.RowDefinitions>
		<i:Interaction.Triggers>
			<ei:PropertyChangedTrigger Binding="{Binding State}">
				<i:Interaction.Behaviors>
					<ei:ConditionBehavior>
						<ei:ConditionalExpression>
							<ei:ComparisonCondition LeftOperand="{Binding State}" RightOperand="FinishedSearch"/>
						</ei:ConditionalExpression>
					</ei:ConditionBehavior>
				</i:Interaction.Behaviors>
				<ei:GoToStateAction StateName="DoneSearching"/>
			</ei:PropertyChangedTrigger>
			<ei:PropertyChangedTrigger Binding="{Binding State}">
				<i:Interaction.Behaviors>
					<ei:ConditionBehavior>
						<ei:ConditionalExpression>
							<ei:ComparisonCondition LeftOperand="{Binding State}" RightOperand="Loaded" />
						</ei:ConditionalExpression>
					</ei:ConditionBehavior>
				</i:Interaction.Behaviors>
				<ei:GoToStateAction StateName="Loaded"/>
			</ei:PropertyChangedTrigger>
			<ei:PropertyChangedTrigger Binding="{Binding State}">
				<i:Interaction.Behaviors>
					<ei:ConditionBehavior>
						<ei:ConditionalExpression>
							<ei:ComparisonCondition LeftOperand="{Binding State}" RightOperand="Unloaded" />
						</ei:ConditionalExpression>
					</ei:ConditionBehavior>
				</i:Interaction.Behaviors>
				<ei:GoToStateAction StateName="Unloaded"/>
			</ei:PropertyChangedTrigger>
		</i:Interaction.Triggers>
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup x:Name="VisualStateGroup">
				<VisualState x:Name="DoneSearching">
					<Storyboard>
						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="MainGrid" BeginTime="0:0:0" AutoReverse="True" >
							<EasingColorKeyFrame KeyTime="0:0:0.4" Value="DarkGreen" />
						</ColorAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState x:Name="Loaded">
					<Storyboard>
						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="MainGrid" BeginTime="0:0:0" AutoReverse="True">
							<EasingColorKeyFrame KeyTime="0:0:0.3" Value="Orange" />
						</ColorAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState x:Name="Unloaded">
					<Storyboard>
						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="MainGrid" BeginTime="0:0:0" AutoReverse="True">
							<EasingColorKeyFrame KeyTime="0:0:0.1" Value="Crimson" />
						</ColorAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>

		<Button Content="Get them tweets!" Width="150" Height="50" HorizontalAlignment="Left" Margin="10" IsDefault="True" Command="{Binding OnSearchClick}" />
		<Button Command="{Binding OnSwitch}" IsTabStop="False" Content="Switch To Prettier View" Height="50" Width="150" VerticalAlignment="Center" />
		<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
			<TextBlock Text="Search String" Foreground="White" Margin="10,0,10,0" VerticalAlignment="Center" />
			<TextBox Text="{Binding SearchString}" Height="26" Width="300" Margin="10,0,0,0" TextWrapping="Wrap" VerticalAlignment="Bottom" Grid.Row="1"/>
		</StackPanel>
		<DataGrid Margin="10,10,10,25" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
								IsReadOnly="True" Grid.Row="2" HorizontalContentAlignment="Stretch" IsSynchronizedWithCurrentItem="True"
								VerticalContentAlignment="Top" AutoGenerateColumns="True" x:Name="dataGrid"
								ItemsSource="{Binding TweetSearchTweets, Mode=OneWay}" />
		<ContentControl x:Name="regionControl" regions:RegionManager.RegionName="BrowserRegion" Grid.Row="3"
						HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" 
						VerticalContentAlignment="Stretch" DataContext="{Binding SelectedItem, ElementName=dataGrid}" />
	</Grid>
</UserControl>
